import { UserEntityName } from "../../controller/user/user.model";
import mongoose, { Schema } from "mongoose";
import IPost from "./post.interface";

const PostEntityName = "Post";
// https://mongoosejs.com/docs/typescript.html
// 1. Imports an interface representing a document in MongoDB.

// 2. Create a Schema corresponding to the document interface.
const postSchema = new Schema<IPost>({
  content: { type: String, required: true },
  author: {
    ref: UserEntityName,
    type: Schema.Types.ObjectId,
    required: true,
  },
  title: { type: String, required: true },
});

//   You as the developer are responsible for ensuring that your document interface lines up with your Mongoose
//   schema. For example, Mongoose won't report an error if email is required in your Mongoose schema but
//   optional in your document interface.
const postModel = mongoose.model<IPost & mongoose.Document>(
  PostEntityName,
  postSchema
);

/**
 * Post 表 的控制器
 */

export { PostEntityName };
export default postModel;
